/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package za.co.pas.business.view.model.list;

import javax.swing.ListModel;
import javax.swing.event.ListDataListener;
import za.co.pas.business.data.UserLoginDetails;

/**
 *
 * @author alabuschagne
 */
public class UserDetailListModel implements ListModel
{
    private UserLoginDetails user = new UserLoginDetails();
    private static final String[] ROW = {"Enabled: ",
                                        "User name: ",
                                        "User type: ",
                                        "First name: ",
                                        "Last name: ",
                                        "E-mail: ",
                                        "Tel: ",
                                        "Cel: ",
                                        "Fax: ",
                                        "Street address: ",
                                        "Postal address: "};
    @Override
    public int getSize()
    {
        return ROW.length;
    }

    @Override
    public Object getElementAt(int index)
    {
        if((getUser() == null) || ((index == 2) && getUser().getUserType() == null) ||((index > 2) && (getUser().getContactPerson() == null)) || ((index == 9) && (getUser().getContactPerson().getStreetAddress() == null)) || ((index == 10) && (getUser().getContactPerson().getPostalAddress() == null)))
        {
            return ROW[index];
        }
        switch(index)
        {
            case 0:
            {
                return ROW[index] + getUser().getEnabled().toString();
            }
            case 1:
            {
                return ROW[index] + getUser().getUserName();
            }
            case 2:
            {
                return ROW[index] + getUser().getUserType().toString();
            }
            case 3:
            {
                return ROW[index] + getUser().getContactPerson().getFirstName();
            }
            case 4:
            {
                return ROW[index] + getUser().getContactPerson().getSurName();
            }
            case 5:
            {
                return ROW[index] + getUser().getContactPerson().getEmail();
            }
            case 6:
            {
                return ROW[index] + getUser().getContactPerson().getTel();
            }
            case 7:
            {
                return ROW[index] + getUser().getContactPerson().getCel();
            }
            case 8:
            {
                return ROW[index] + getUser().getContactPerson().getFax();
            }
            case 9:
            {
                return ROW[index] + getUser().getContactPerson().getStreetAddress().toString();
            }
            case 10:
            {
                return ROW[index] + getUser().getContactPerson().getPostalAddress().toString();
            }
        }
        return null;
    }

    @Override
    public void addListDataListener(ListDataListener l)
    {
    }

    @Override
    public void removeListDataListener(ListDataListener l)
    {
    }

    public void setUser(UserLoginDetails elementAt)
    {
        this.user = elementAt;
    }

    /**
     * @return the user
     */
    public UserLoginDetails getUser()
    {
        return user;
    }


}
